# -*- Mode: Python -*- vi:si:et:sw=4:sts=4:ts=4:syntax=python


class Recipe(recipe.Recipe):
    name = 'libxml2'
    version = '2.9.7'
    stype = SourceType.TARBALL
    # Upstream still has a broken SSL certificate, use our mirror
    #url = 'https://xmlsoft.org/sources/libxml2-%(version)s.tar.gz'
    url = 'https://gstreamer.freedesktop.org/src/mirror/libxml2-%(version)s.tar.gz'
    tarball_checksum = 'f63c5e7d30362ed28b38bfa1ac6313f9a80230720b7fb6c80575eeab3ff5900c'
    licenses = [{License.MIT: ['COPYING']}]
    deps = [ 'zlib' ]
    autoreconf = True
    patches = ['libxml2/0003-configure-fix-python-dir-prefix.patch']

    files_libs = ['libxml2']
    files_devel = ['include/libxml2', 'lib/xml2Conf.sh', 'bin/xml2-config',
                   'lib/pkgconfig/libxml-2.0.pc', 'bin/xmllint%(bext)s']

    def prepare(self):
        if self.config.target_platform == Platform.WINDOWS:
            self.configure_options = '--with-python=no'
            self.configure_options += ' --without-threads'
        elif self.config.target_platform == Platform.ANDROID:
            self.configure_options = '--with-python=no'
            v = DistroVersion.get_android_api_version(self.config.target_distro_version)
            if v < 21:
                self.append_env('CFLAGS', '-D_FILE_OFFSET_BITS=32')
                self.append_env('CPPFLAGS', '-D_FILE_OFFSET_BITS=32')
        elif self.config.target_platform == Platform.IOS:
            self.configure_options = '--with-python=no'
        elif self.config.target_platform == Platform.LINUX:
            self.configure_options = '--with-python=no'
